import { createStore } from 'vuex'
import {getCart} from 'network/cart.js'
export default createStore({
  state: {
    user:{
      isLogin:window.localStorage.getItem('token')?true:false
    },
    cartCount:1
  },
  mutations: {
    setIsLogin(state,payload){
      state.user.isLogin=payload
    },
    addCart(state,payload){
        state.cartCount=payload.count
    }
  },
  actions: {
    updateCart({commit}){
      getCart().then(res=>{
          commit('addCart',{count:res.data.length||0})
      })
    }
  },
  modules: {
  }
})
